<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />

		<title></title>
		<script src="../../js/mui.min.js"></script>
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<!--App自定义的css-->
		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" href="../../css/global.css">
		<link rel="stylesheet" type="text/css" href="../../css/app.css" />
		<link rel="stylesheet" type="text/css" href="../../css/app.css" />
		<link rel="stylesheet" type="text/css" href="../../css/mui.picker.min.css" />
		<script src="../../js/mui.picker.min.js"></script>
		<script src="../../js/getURLParam.js"></script>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav headerstyle" >
			<a class="mui-action-back astyle"><img src="../../images/drawable-hdpi/head_back.png"/></a>
			<span id="title">搜索</span>
		</header>
		<!--<div id="test">test</div>
		<div id="test1">test1</div>-->
		<!--<div style="width: 100%;text-align: center;">
			<span>添加对比车辆</span>
			<hr style="color: red;" />
		</div>-->
		<div class="mui-content" style="width: 100%;text-align: center;margin-top: 0px;">
			<!--<ul class="mui-table-view" style="float: left;width: 100%;">
				<li class="mui-table-view-cell" style="text-align: center;">
					
				</li>
			</ul>-->
			<div style="margin-top: 10px;margin-left: 10px;margin-right: 10px;">
			<input type="text" readonly="readonly" style="width: 100%;text-align: center;" id="vclnum"></input>
			<button id='begdate' style="float:left;width: 45%;" data-options='{"type":"date","beginYear":2014,"endYear":2016}' class="btn mui-btn mui-btn-block">选择开始日期 </button>
			<button id='enddate' style="float:right;width: 45%;;" data-options='{"type":"date","beginYear":2014,"endYear":2016}' class="btn mui-btn mui-btn-block">选择结束日期 </button>
			</div>
			
		</div>
		<div class="mui-content" style="margin: 10px;">
			<button type="button" class="mui-btn mui-btn-block mui-btn-primary" onclick="add()">添加对比</button>
		</div>
		<script>
			mui.init({
				swipeBack: true //启用右滑关闭功能
			});
			(function($) {
				$.init();
				//var result = $('#demo2')[0];
				var btns = $('.btn');
				btns.each(function(i, btn) {
					btn.addEventListener('tap', function() {
						var optionsJson = this.getAttribute('data-options') || '{}';
						var options = JSON.parse(optionsJson);
						var id = this.getAttribute('id');
						var picker = new $.DtPicker(options);
						picker.show(function(rs) {
							//result.innerHTML=rs.text;
							document.getElementById(id).innerHTML=rs.text;
							//mui.toast(rs.text) ;
						});
					}, false);
				});
			})(mui);
			var sessionid=GetQueryString("sessionid");
			var accountid=GetQueryString("accountid");
	        var proversion=GetQueryString("proversion");
	        var vclid=GetQueryString("vclid");
	        var vclnum=GetQueryString("vclnum");
	        document.getElementById("vclnum").value=vclnum;
	        var nowdate = new Date();
	        var today = new Date();
	        var month = today.getMonth()+1;
	        if(month<10){
	        	month="0"+month;
	        }
	        today = today.getFullYear()+"-"+month+"-"+today.getDate();
	        nowdate.setFullYear(nowdate.getFullYear()-1);
	        var nowyear = nowdate.getFullYear();
	        document.getElementById("begdate").setAttribute("data-options",'{"type":"date","beginYear":'+nowyear+',"endYear":2099}');
			document.getElementById("enddate").setAttribute("data-options",'{"type":"date","beginYear":'+nowyear+',"endYear":2099}');	        
			function add(){
				var begtime = document.getElementById("begdate").innerHTML;
				var endtime = document.getElementById("enddate").innerHTML;
				if(begtime.length!=10){
					mui.toast(begtime);
					return false;
				}
				if(endtime.length!=10){
					mui.toast(endtime);
					return false;
				}

				var bd = new Date(begtime);
				var ed = new Date(endtime);
				var td = new Date(today);
				//mui.toast(today==begtime)
				if(bd>td){
					mui.toast("开始日期不能大于当前日期!");
					return false;
				}
				if(ed>td){
					//document.getElementById("dd").innerHTML=bd.getFullYear();
					mui.toast("结束日期不能大于当前日期!");
					return false;
				}
				if(today==begtime){
					mui.toast("开始日期不能选择当前日期!");
					return false;
				}
				if(today==endtime){
					//document.getElementById("dd").innerHTML=bd.getFullYear();
					mui.toast("结束日期不能选择当前日期!");
					return false;
				}
				if(bd>ed){
					//document.getElementById("dd").innerHTML=bd.getFullYear();
					mui.toast("开始日期不能大于结束日期!");
					return false;
				}
				var aDate = begtime.split("-")   
				var oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) //转换为12-18-2002格式   
				var aDate = endtime.split("-")   
				var oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])   
				var iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24) //把相差的毫秒数转换为天数   
				if(iDays>30){
					mui.toast("日期间隔不能大于30天!");
					return false;
				}
				mui.ajax('../../../APP/anayList', {
				data: {
					param: '{"proVersion":"' + proversion + '","accountId":"' + accountid + '","sessionid":"' + sessionid + '","data":{"type":"2","vclId":"'+vclid+'","beTime":"' + begtime + '","endTime":"' + endtime + '"}}'
				},
				dataType: 'jsonp', //服务器返回json格式数据
				type: 'post', //HTTP请求类型
				timeout: 10000, //超时时间设置为10秒；
				success: function(data) {
					var jsonObj = window.JSON.parse(data);
					if (jsonObj.resultcode == "1") {
						window.location.href="expertvcllist.html?sessionid="+sessionid+"&accountid="+accountid+"&proversion="+proversion;
					} else if(jsonObj.resultcode == "122") {
						mui.toast("最多可添加20台");
					}
				},
				error: function(xhr, type, errorThrown) {
					//document.getElementById("test").innerHTML="err";
				}
			});
			}
		</script>
	</body>

</html>